
Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';


//树形结构

var record_start = 0; 

var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",
width:40, 
renderer:function(value,metadata,record,rowIndex){ 
return record_start + 1 + rowIndex; 
} 
}),
{header:'债项流水号',dataIndex:'debtNo',width:100,hidden:true},
{header:'债项编号',dataIndex:'debtId',width:100},
{header:'债项名称',dataIndex:'debtDesc',width:100},
{header:'债项业务品种',dataIndex:'debtType',width:130}, 
{header:'债项币种',dataIndex:'currency',width:100},
{header:'合同金额(元)',dataIndex:'debtSum',width:100},
{header:'债项余额(元)',dataIndex:'debtBalance',width:100},
{header:'到期日',dataIndex:'endDate',width:100},
{header:'授信形式',dataIndex:'businessKind',width:100,hidden:true},
{header:'担保类型',dataIndex:'guarantyKind',width:100,hidden:true},
{header:'LGD(%)',dataIndex:'lgd',width:100},
{header:'EC(元)',dataIndex:'ec',width:100,hidden:true},
{header:'RAROC(%)',dataIndex:'raroc',width:100},
{header:'建议最低贷款利率(%)',dataIndex:'riskPrice',width:200},
]); 
var ds=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'riskApp/listPriceRarocDebt.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ 
totalProperty:'total',  
root:'resultData'},[
{name:'debtNo'},
{name:'debtId'}, 
{name:'debtDesc'},  
{name:'debtType'},
{name:'debtSum'},
{name:'currency'}, 
{name:'debtBalance'}, 
{name:'startDate'}, 
{name:'endDate'},  
{name:'businessKind'},
{name:'guarantyKind'},
{name:'groupLoanType'}, 
{name:'lgd'},  
{name:'ead'},
{name:'rwa'},  
{name:'ec'},
{name:'raroc'},
{name:'riskPrice'},
]) 
}); 

var addCurrencyStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=Currency',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addBusinessKindStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=BusinessKind',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
,
autoLoad:true
}); 

var addGuarantyKindStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=GuarantyKind',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addGroupLoanTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=YesNo',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 


var grid=new Ext.grid.GridPanel({ 
id:'myCustomers',
renderTo:"rating_list", 
stripeRows:true,//斑马线效果
title:"债项信息", 
height:500, 
cm:cm,
store: ds, 
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 20,   
                store: ds,   
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据" ,
                doLoad : function(start){ 
   record_start = start; 
var o = {}, pn = this.getParams(); 
          o[pn.start] = start; 
          o[pn.limit] = this.pageSize; 
this.store.load({params:o}); 
     }  
            }),
 tbar: [
 {text:'定价测算',handler: startDebtRating}
 ]              
});
ds.load({params:{start:0,limit:20}}); 


//新增客户表单
addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
width: 580, 
height: 250, 
//样式 
bodyStyle: 'margin:3px 3px 3px 3px', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
title: '债项评级', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'debtNo',
	name: 'debtNo', 
	fieldLabel: '债项编号', 
	readOnly:true,
	width: 150
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'debtDesc',
	name: 'debtDesc', 
	fieldLabel: '债项名称', 
	emptyText: '必填', 
	blankText: '债项名称不能为空', 
	allowBlank: false, 
	readOnly:true,
	width: 150
}
]} 
]},

{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
			xtype: 'combo', 
			 	id : "debtType",
              store :addBusinessKindStore,
              fieldLabel: '债项业务品种',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              readOnly:true,
              mode:'remote', 
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'debtType'
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
			xtype: 'combo', 
 			id : "currency",
              store :addCurrencyStore,
              fieldLabel: '债项币种',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              readOnly:true,
              mode:'remote', 
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'currency'
}
]} 
]},

	
	
	{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id: 'debtSum',
	name: 'debtSum', 
	fieldLabel: '债项金额', 
	emptyText: '必填', 
	readOnly:true,
	blankText: '债项金额不能为空', 
	allowBlank: false,  
	regex:  /^[0-9]+(.[0-9]{1,9})?$/,
 	regexText:'只能输入整数或小数！' , 
	width: 150
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
	id: 'debtBalance',
	name: 'debtBalance', 
	fieldLabel: '债项余额', 
	emptyText: '必填', 
	blankText: '债项金额不能为空', 
	allowBlank: false,  
	regex:/^[0-9]+\.{0,1}[0-9]{0,9}$/,
 	regexText:'只能输入整数或小数！' , 
	width: 150
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
           xtype: 'datefield',
id: 'startDate', 
name: 'startDate', 
fieldLabel: '起始日',
allowBlank: true,
editable:false,  
format : 'Y-m-d' ,
readOnly:true,
width: 150
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
           xtype: 'datefield',
id: 'endDate', 
name: 'endDate', 
fieldLabel: '到期日',
allowBlank: true,
editable:false,  
readOnly:true,
format : 'Y-m-d' ,
width: 150
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
          xtype: 'combo', 
 id : "businessKind",
              store :addBusinessKindStore,
              fieldLabel: '授信形式',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              mode:'remote', 
              readOnly:true,
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'businessKind'
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
         xtype: 'combo', 
 id : "guarantyKind",
              store :addGuarantyKindStore,
            fieldLabel: '担保类型',
              valueField : 'code',
              displayField : 'name',
              editable: false,
              typeAhead : true,
              width: 150,
              readOnly:true,
              mode:'remote',  
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'guarantyKind'
}
]} 
]},
	
	{layout : "form",
	items : [	{ 
xtype: 'combo', 
 id : "groupLoanType",
              store :addGroupLoanTypeStore,
              fieldLabel: '是否是银团贷款',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              readOnly:true,
              mode:'remote',  
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'groupLoanType'
	}]},	

] 
}],
buttonAlign:'right',
buttons: 
[  
{ text: '计算' } ,
{ text: '关闭', handler: function() { Ext.getCmp('addWin').hide(); } }
],
});


//新增客户表单
resultForm = new Ext.form.FormPanel({ 
id: 'resultForm', 
width: 580, 
height: 100, 
//样式 
bodyStyle: 'margin:3px 3px 3px 3px', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
title: '计算结果', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'lgd',
	name: 'lgd', 
	fieldLabel: 'LGD', 
	readOnly:true,
	width: 150
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'ead',
	name: 'ead', 
	fieldLabel: 'EAD', 
	readOnly:true,
	width: 150
}
]} 
]},
] 
}],


});


//新增用户窗口 
addWin = new Ext.Window({ 
id: 'addWin', 
title: '债项评级', 
width: 600, 
height: 400, 
//背景遮罩 
modal: true, 
//重置大小 
resizable: false, 
//当关闭按钮被点击时执行的动作 
closeAction: 'hide', 
plain: true, 
buttonAlign: 'center', 
items:[addForm,resultForm],

});

function startDebtRating(){
if (grid.getSelectionModel().getSelections()[0] == undefined) { 
	Ext.Msg.alert("提示", "请选中要查看的内容！"); 
}
else{
	var selectedId = grid.getSelectionModel().getSelections()[0].data.debtNo;
   // alert(selectedId);
   	
   	addForm.form.reset(); 
	//Ext.getCmp('acBtn').hide();
	//addWin.buttons[0].handler = editFunction; 

	Ext.Ajax.request({
  		url:'checkRequest.do',
	    method:'GET',
  		success:function(){
 			 window.location.href="riskApp/computeRaroc.do?debtNo="+selectedId;
  		},failure:function(){
    	Ext.MessageBox.alert("请求异常！");
  	}
}
	); 
}
}

function editFunction(){
if(addForm.form.isValid()){
	 addForm.form.doAction('submit', { 
        url : 'obligation/editDebtCollateral.do', 
        method : 'post', 
		success : function() {
		 	Ext.getCmp("addWin").hide();
			grid.store.reload();
			Ext.Msg.alert('提示', '编辑成功！'); 
		}, 
        failure : function() { 
			Ext.Msg.alert('提示', '编辑失败！'); 
 		} 
	}); 
}
}

function PDDetail(){
	window.location.href="view/rating/CustomerRating_RatingProcess.jsp";
}

function rowdblclickFn(grid, rowIndex, e){//双击事件  
             var row = grid.getStore().getAt(rowIndex); 
             var selectedCustId = row.get("custId");
             Ext.Ajax.request({
  url:'checkRequest.do',
  method:'GET',
  success:function(){
  window.location.href="customer/checkMyCustomer.do?CustId="+selectedCustId;
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});  
           //  window.location.href="view/customer/CheckCustomer_General.jsp?custId="+selectedCustId;
        }   
        grid.addListener('rowdblclick',startDebtRating);
/*grid.on('rowdblclick',function(){ window.location.href="view/customer/CheckCustomer_General.jsp" });*/
}); 